package com.gxa.modules.service.impl;


import com.gxa.common.vo.R;
import com.gxa.modules.mapper.SysUserMapper;
import com.gxa.modules.pojo.Sys_User;
import com.gxa.modules.service.SysUserService;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public R register(Sys_User sys_user) {
        R r = new R();
        //以后可以将盐值生成一个随机数
        String salt = "gxa";
        //盐值
        SimpleHash simpleHash = new SimpleHash("md5",sys_user.getPassword(),salt,3);
        //密码加密+加盐+散列==新的密码
        sys_user.setPassword(simpleHash.toString());
        //将盐值
        sys_user.setSalt(salt);
        //调用Mapper实现添加系统用户
        int result = sysUserMapper.addSysUser(sys_user);
        if (result > 0){
            r.setCode(200);
            r.setMsg("注册成功");
        }
        return r;
    }

}
